package com.weilong.lw.myunittestdemo.toolbar2;

import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;

import com.weilong.lw.myunittestdemo.R;
import com.weilong.lw.myunittestdemo.toolbar2.widget.MyTool;
/*
 *对toolbar进行封装
 * 不同于toolbar简单封装
 * 继承toolbar并将其改写成自己想要的样式，其中添加接口
 */

public class Toolbar1Activity extends AppCompatActivity {
    MyTool toolbar;
    int Flag=0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_toolbar);
        toolbar = (MyTool) findViewById(R.id.toolbar);
        toolbar.setOnLeftButtonClickListener(new MyTool.OnLeftButtonClickListener() {
            @Override
            public void onClick() {
                finish();
            }
        });
        //过时
        //toolbar.setRightButtonIconDrawable(getResources().getDrawable(R.drawable.arrow_left));
//        toolbar.setRightButtonIconDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.search_right, null));
        //以下2中未过时
        toolbar.setRightButtonIconDrawable(ContextCompat.getDrawable(this, R.drawable.search_right));
//        toolbar.setRightButtonIconDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.search_right, null));
        toolbar.setOnRightButtonClickListener(new MyTool.OnRightButtonClickListener() {
            @Override
            public void onClick() {
                if (Flag==0) {
                    toolbar.setShowSearchView();
                    Flag=1;
                }else if (Flag==1){
                    Flag=0;
                    toolbar.setShowTitleView("首页");
                }
            }
        });


    }
}
